package com.liner;

import java.util.Scanner;

/**
 * 随机加法运算器
 */
public class Addition {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        /*
         * 随机10道一百以内加法  算吧 答对了，答错了
         * 总分 答对1题 10分 ， 答错不扣分
         */
        int num1, num2, sum;
        int score = 0;
        System.out.println("两位数加减法考一考：");
        for (int i = 1; i <= 10; i++) {
            //随机生成 两位数
            num1 = (int) (Math.random() * 100);
            num2 = (int) (Math.random() * 100);

            System.out.println("第" + i + "题:  ");
            //判断题号 是奇数就是减法，偶数就是加法
            if ((i & 1) == 0) {
                //加法
                System.out.println(num1 + " + " + num2 + " = ");
                System.out.print("你的答案是: ");
                sum = scanner.nextInt();
                if (sum == (num1 + num2)) {
                    System.out.println("恭喜你答对了");
                    score += 10;
                } else {
                    System.out.println("很遗憾答错了");
                }


            } else {
                //减法
                System.out.println(num1 + " - " + num2 + " = ");
                System.out.print("你的答案是: ");
                sum = scanner.nextInt();
                if (sum == (num1 - num2)) {
                    System.out.println("恭喜你答对了");
                    score += 10;
                } else {
                    System.out.println("很遗憾答错了");
                }

            }


        }
        System.out.println("本次得分：" + score);


    }
}
